//
//  Constants.swift
//  Z048
//
//  Created by remy on 2020/3/1.
//  Copyright © 2020 remy. All rights reserved.
//

struct Constants {
    static let xCount: Int = 4
    static let yCount: Int = 4
    static let count: Int = xCount * yCount
    static let stageSize: CGSize = {
        let value = Size.screenWidth - 32.0
        return CGSize(width: value, height: value)
    }()
    static let blockSize: CGSize = {
        let value = ((stageSize.width - spacing * CGFloat(xCount - 1)) / CGFloat(xCount)).rounded()
        return CGSize(width: value, height: value)
    }()
    static let spacing: CGFloat = (stageSize.width / CGFloat(xCount - 1 + xCount * 10)).rounded()
    static let baseOffset: CGPoint = {
        let x = (blockSize.width - stageSize.width) * 0.5
        let y = (blockSize.height - stageSize.height) * 0.5
        return CGPoint(x: x, y: y)
    }()
    /**
     e.g.
     ```
     12 13 14 15
     8  9  10 11
     4  5  6  7
     0  1  2  3
     ```
     */
    static let points: [CGPoint] = {
        var points: [CGPoint] = []
        (0..<count).forEach {
            let x = CGFloat($0 % xCount) * (blockSize.width + spacing) + baseOffset.x
            let y = CGFloat($0 / yCount) * (blockSize.height + spacing) + baseOffset.y
            points.append(CGPoint(x: x, y: y))
        }
        return points
    }()
}
